package com.groupbuying.sysconfig.dto.app;

import com.alibaba.fastjson.JSONObject;

/**
 * @Description 支付宝生活号格式化数据工具类
 * @Author Davidbieber
 * @Email davidbieber@163.com
 * @Date 2019/10/25 10:09 上午
 */
public class DataFormatForAlipayApp {

    public static JSONObject create(AppAlipayInfo appAlipayInfo){
        JSONObject jsonParams=new JSONObject();
        jsonParams.put("to_user_id",appAlipayInfo.getToUserId());
        JSONObject temParams=new JSONObject();
        JSONObject dataJson=new JSONObject();
        dataJson.put("headColor",appAlipayInfo.getHeadColor());
        dataJson.put("url",appAlipayInfo.getUrl());
        dataJson.put("action_name",appAlipayInfo.getActionName());
        for (AppDataInfo datum : appAlipayInfo.getData()) {
            JSONObject dataTem = new JSONObject();
            dataTem.put("value", datum.getValue());
            dataTem.put("color",datum.getColor());
            dataJson.put(datum.getName(), dataTem);
        }
        temParams.put("context",dataJson);
        temParams.put("template_id",appAlipayInfo.getTemplateId());
        jsonParams.put("template",temParams);
        return jsonParams;
    }
}
